package com.ewhale.feitengguest.presenter.shop.mine

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.AliAuthInfoDto
import com.ewhale.feitengguest.dto.AuthInfoDto
import com.ewhale.feitengguest.dto.ShopAuthDto
import com.ewhale.feitengguest.view.shop.mine.SMineView
import com.ewhale.feitengguest.view.shop.mine.ShopAuthView
import com.ewhale.feitengguest.view.user.mine.UserInfoView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException

/**
 * 作者：SimGa
 * 日期：2020/1/2
 * 时间：11:17
 * 包名：com.ewhale.feitengguest.presenter.shop.task
 */
class SMinePresenter : IPresenter() {
    fun resetHeadPhoto(image: String) {
        mView.showProLoading()
        request(1, ApiHelper.USER_API.resetHeadPhoto("app/shop/updateHeadPhoto.json",image), image)
    }


    fun resetNickName(name: String) {
        mView.showProLoading()
        request(2, ApiHelper.USER_API.resetNickName("app/shop/updateNickName.json",name), name)
    }

    fun getAuthInfo() {
        request(3, ApiHelper.USER_API.authentication, null)
    }

    override fun <T> onNext(postCode: Int, result: T?, data: Any?) {
        super.onNext(postCode, result, data)
        when (postCode) {
            1 -> (mView as SMineView).resetAvatar(data as String)
            2 -> (mView as SMineView).resetName(data as String)
            3->{
                if (result == null) {
                    mView.showErrorMessage(postCode, "null", "")
                } else {
                    (mView as SMineView).showAuthInfo(result as ShopAuthDto)
                }
            }
        }
    }

    override fun otherException(postCode: Int, data: Any?, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode, e!!.code, e.displayMessage)
    }

}
